
package com.timber.util;


import java.awt.*;
import javax.swing.*;
import pv.jfcx.*;
import java.text.*;


public class SLNumberRenderer extends DefaultSLObjectRenderer
{

  protected boolean zeroAsNull = true;

  public SLNumberRenderer( int type, boolean zeroAsNull )
  {
    super(type);
    this.zeroAsNull = zeroAsNull;
  }

  public SLNumberRenderer( int type )
  {
    super(type);
  }


  public SLNumberRenderer( int type, int integerPlaces, int decimalPlaces, int alignment )
  {
    super(type);

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumIntegerDigits( integerPlaces );
    nf.setMaximumFractionDigits( decimalPlaces );
    nf.setMinimumFractionDigits( decimalPlaces );

    m_format = nf;

    setHorizontalAlignment( alignment );

  }

  public SLNumberRenderer( int type, int integerPlaces, int decimalPlaces, int alignment, boolean zeroAsNull )
  {
    this( type, integerPlaces, decimalPlaces, alignment );
    this.zeroAsNull = zeroAsNull;
  }

  public SLNumberRenderer( int type, int integerPlaces )
  {
    this( type, integerPlaces, 0, SwingConstants.RIGHT );
  }

  public SLNumberRenderer( int type, int integerPlaces, boolean zeroAsNull )
  {
    this( type, integerPlaces );
    this.zeroAsNull = zeroAsNull;
  }

  public SLNumberRenderer( int type, int integerPlaces, int decimalPlaces )
  {
    this( type, integerPlaces, decimalPlaces, SwingConstants.RIGHT );
  }

  public SLNumberRenderer( int type, int integerPlaces, int decimalPlaces, boolean zeroAsNull )
  {
    this( type, integerPlaces, decimalPlaces, SwingConstants.RIGHT,zeroAsNull );
    
  }

  public Component getTableCellRendererComponent( JTable  t,
						  Object  o,
						  boolean sel,
						  boolean foc,
						  int     row,
						  int     col )
  {
    if( zeroAsNull == true )
    {
      if( o != null && o instanceof Number && ( (Number)o ).doubleValue() == 0.0 )
	o = null;
    }

    Component ret = super.getTableCellRendererComponent( t, o, sel, foc, row, col );
    return ret;

  }


}
